package com.jn.mvvm2.repository;

import com.jn.mvvm2.service.PetService;
import com.jn.mvvm2.entity.Pet;
import java.util.List;
import retrofit2.Retrofit;
import retrofit2.converter.gson.GsonConverterFactory;

public class PetRepository {
    private PetService petService;
    private List<Pet> petList;

    public PetRepository() {
        Retrofit retrofit = new Retrofit.Builder()
                .baseUrl("https://your-api-base-url/")
                .addConverterFactory(GsonConverterFactory.create())
                .build();

        petService = retrofit.create(PetService.class);
        petList = fetchPetsFromNetwork(); // 从网络获取所有宠物数据
    }

    private List<Pet> fetchPetsFromNetwork() {
        // 异步调用网络请求获取数据
        // 注意：实际开发中应使用异步方式调用，例如使用RxJava或Coroutines
        return petService.getAllPets().execute().body();
    }

    public List<Pet> getPetList() {
        return petList;
    }
}